//
//  AlbumCell.m
//  AlbumDemo
//
//  Created by nadyboy on 2018/1/29.
//  Copyright © 2018年 hejinhui. All rights reserved.
//

#import "AlbumCell.h"
#import "AlbumCellModel.h"
#import "AlbumCellPhoto.h"
@interface AlbumCell()
{
    CGRect _rect;
}
//图片
@property(nonatomic,strong)UIImageView *photoImgV;
//按钮
@property(nonatomic,strong)UIButton *addBtn;
//标题
@property(nonatomic,strong)UILabel *titLabel;

@end

@implementation AlbumCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setCellModel:(AlbumCellModel *)cellModel
{
    _cellModel = cellModel;
    _rect = cellModel.cellFrame;
    
    AlbumCellPhoto  *photo = [cellModel.photos lastObject];
    self.photoImgV.image = photo.image;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.photoImgV];
        [self addSubview:self.addBtn];
        [self addSubview:self.titLabel];
    }
    return self;
}
//初始化
-(UIImageView *)photoImgV
{
    if (!_photoImgV) {
        _photoImgV = [[UIImageView alloc]init];
    }
    return _photoImgV;
}

-(UIButton *)addBtn
{
    if (!_addBtn) {
        
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _addBtn.backgroundColor = [UIColor orangeColor];
        [_addBtn setImage:[UIImage imageNamed:@"ic_addphoto"] forState:UIControlStateNormal];
        [_addBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addBtn;
}

-(UILabel *)titLabel
{
    if (!_titLabel) {
        _titLabel = [[UILabel alloc]init];
        _titLabel.textAlignment = NSTextAlignmentCenter;
        _titLabel.textColor = [UIColor darkTextColor];
        _titLabel.font = [UIFont systemFontOfSize:10];
    }
    return _titLabel;
}

-(void)btnClick:(UIButton *)sender
{
//    if (self.itemBlock) {
//        self.itemBlock(self);
//    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    //imageView的frame
    self.photoImgV.frame = CGRectMake(0, 0, _rect.size.width, _rect.size.height - 30);

    //title的frame
    self.titLabel.frame = CGRectMake(0, CGRectGetMaxY(self.photoImgV.frame), _rect.size.width - 30, 30);

    //addBtn的frame
    self.addBtn.frame = CGRectMake(_rect.size.width - 30, CGRectGetMinY(self.titLabel.frame), 25,25);
}



@end
